//
//  DrawPickView.m
//  YiJuZhangShou2.0
//
//  Created by URANUS on 16/3/24.
//  Copyright © 2016年 Mr.X. All rights reserved.
//

#import "DrawPickBooleanView.h"

@implementation DrawPickBooleanView

#pragma mark Overried
-(void)drawRect:(CGRect)rect{
    // 下面两句代码的作用就是填充背景色(注意这里设置后，外面的backgroundColor设置会无效)
//    [[UIColor whiteColor] setFill];
//    UIRectFill(rect);
    
    CGFloat width = CGRectGetWidth(rect);
    CGFloat height = CGRectGetHeight(rect);
    CGFloat centerX = width/2;
    CGFloat centerY = height/2;
    CGFloat radius = (width>height?height:width)/2*0.7;
    
    //获取当前环境
    CGContextRef context = UIGraphicsGetCurrentContext();
    //保存当前环境，便于以后恢复
    CGContextSaveGState(context);
    CGContextDrawPath(context, kCGPathFillStroke);
    
    UIBezierPath *path = [UIBezierPath bezierPath];
    
    CGPoint firstPoint = CGPointMake(centerX - radius*0.9, height-radius);
    CGPoint secondPoint = CGPointMake(radius, centerY+radius);
    CGPoint thirdPoint = CGPointMake(centerX+radius, centerY-radius*0.8);
    [path moveToPoint:firstPoint];
    [path addLineToPoint:secondPoint];
    [path addLineToPoint:thirdPoint];
    [path setLineWidth:width/10];
    //设置连接处类型：（这里为圆角）
    [path setLineJoinStyle:kCGLineJoinRound];
    //设置边不连接处类型：（这里为圆角）
    [path setLineCapStyle:kCGLineCapRound];
    [path setLineWidth:3];
#ifndef StartStrokeColor
#define StartStrokeColor [UIColor blackColor]
#endif
    UIColor *strokeColor = self.strokeColor == nil ? StartStrokeColor:self.strokeColor;
    [strokeColor setStroke];
    [path stroke];
}

#pragma mark Setter
-(void)setBorderColor:(UIColor *)borderColor{
    self.layer.masksToBounds = YES;
    self.layer.borderWidth = 1;
    self.layer.borderColor = borderColor.CGColor;
}

-(void)setStrokeColor:(UIColor *)strokeColor{
    _strokeColor = strokeColor;
    [self setNeedsDisplay];
}

@end
